layui.define([ 'form','layer','memberApi','laydate','laytpl' ], function(exports) {
    var view = {};
    var form = layui.form;
    var $ = layui.$;
    var laydate = layui.laydate;
    var laytpl = layui.laytpl;
    var memberApi = layui.memberApi;
    var articleListViewId = "articleListView";
    var articleListViewTplId = "articleListTpl";

    $(document).on("click",".article_del",function() {
        var id = $(this).attr("articleId");
        memberApi.articleDel(id,function() {
            Common.info("删除成功");
            initArticleList(articleListViewId,1,10);
        });
    })

    function initArticleList(id, page,limit) {
        var $el = $("#" + id);
        var memberId = $el.attr("member_id");
        if (!page) page = 1;
        if (!limit) limit = 10;
        $.post(Common.ctxPath + "/article/list.json",{memberId:memberId,page:page,limit:limit},function(resp) {
           resp.limit = limit;
           console.log(resp);
           var articleListTpl = document.getElementById(articleListViewTplId);
           if (articleListTpl) {
               var getTpl = articleListTpl.innerHTML;
               laytpl(getTpl).render(resp, function(html){
                  articleListView.innerHTML = html;
               });
           }
       });
    }

    function initArticleListPage(count,curr,limit) {
        return laypage.render({
            elem: 'articlePage'
            ,count: count
            ,curr:curr
            ,limit:limit
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            ,jump: function(obj,first){
              //首次不执行
              if(!first){
                  initArticleList(articleListViewId, obj.curr,limit);
              }
            }
          });
    }

    initArticleList(articleListViewId,1,10);

	exports('articles', view);
});